package interface_func

import "fmt"

type CoreConf interface {
	getServiceName() string
	GetMicroAddress() string
	GetLogSample() bool
}

func ConfLoad() {
	////todo 配置文件读取或者请求配置中心服务
	Conf.LogSample = true
	Conf.ServiceName = "yorm.com"
	Conf.MicroAddress = "182.272.212.110"
	fmt.Println("初始化配置")
}

type AppConf struct {
	Conf CoreConf
}

func (app *AppConf) run() {
	ConfLoad()
	fmt.Println("服务名称：", app.Conf.getServiceName())
	fmt.Println("服务地址：", app.Conf.GetMicroAddress())
	fmt.Println("日志采样：", app.Conf.GetLogSample())
}

var (
	Conf          = new(config)
	_    CoreConf = new(config)
)

type config struct {
	ServiceName  string `yaml:"serviceName" json:"serviceName"`
	LogSample    bool   `yaml:"logSample" json:"logSample"`
	MicroAddress string `yaml:"microAddress" json:"microAddress"`
}

func (c *config) getServiceName() string {
	return c.ServiceName
}

func (c *config) GetLogSample() bool {
	return c.LogSample
}

func (c *config) GetMicroAddress() string {
	return c.MicroAddress
}
